<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Service\ChCustomerServiceService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\DeleteMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\PutMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: 'ch/attract/customerService'),ApiAuth,VerifySignature]
class ChCustomerServiceController extends BaseController
{
    #[Inject]
    protected ChCustomerServiceService $service;

    /**
     * 客服列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('list')]
    public function getCustomerServiceList()
    {
        return $this->success($this->service->getCustomerServiceList($this->request->all()));
    }

    /**
     * 新增客服
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function saveCustomerService()
    {
        return $this->success(['id' => $this->service->saveCustomerService($this->request->all())]);
    }

    /**
     * 更新客服
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PutMapping('update')]
    public function updateCustomerService()
    {
        return $this->service->update($this->request->input('id'),$this->request->all())?$this->success():$this->error();
    }

    /**
     * 删除客服
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[DeleteMapping('delete')]
    public function deleteCustomerService()
    {
        return $this->service->deleteCustomerService((int)$this->request->input('id'))?$this->success():$this->error();
    }
}